<?php
/**
 * Created by PhpStorm.
 * UsersF: Mloong
 * Date: 2018/12/17
 * Time: 11:10
 */

namespace app\api\model;


use think\Model;

class Account extends Model
{
    /**
     * 查找登陆的权限
     * @param $name
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getScope($name)
    {
        return self::where('name','=',$name)
            ->find()
            ->value('scope');
    }

    public static function getAllAccountName()
    {
        return self::where('status', '=', 1)
            ->select()
            ->column('name');
    }

    public static function getAllAccount()
    {
        return self::where('status', '=', 1)
            ->select()
            ->toArray();
    }

    # 关联注册记录表
    public function pop()
    {
        return $this->hasMany('Registered','from', 'name');
    }

    public function getIps()
    {
        return self::with([
            'pop' => function($query){
                $query->whereTime('add_time', 'yesterday')
                ;
            }
        ])  ->select()
            ->toArray();
    }
}